var fs = require('fs');
var path = require('path');
var DxfStruct = require('./DxfStruct2');
var DxfParser = require('../');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'as.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });
var parser = new DxfParser();
var layer_color = {}

parser.parseStream(fileStream, function (err, dxf) {
    if (err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));
    dxf.sys = { start: 371, points: [], dn: 400 }
    dxfstruct = new DxfStruct(dxf)
    var blocks = ['gc304', 'gc178', 'gc214', 'GC026', 'gc104', 'GC101', 'GC021', 'GC023', 'GC020', 'gc309', 'GC030',
        'gc022', 'GC103', 'gc019', 'gc029', 'bc128', 'gc302', 'gc075', 'gc310', 'gc203', 'GC105',
        'gc106', '47.00-99.00', '*D91', 'DLSS', 'JMD', 'SXSS', '给水']
    var layers = ['0','JMD']//'DLSS','JMD','SXSS','给水内业点号','给水线注记'
    var merge = ['DLSS','JMD','SXSS']
    
    var newLayer = {
        layer:['SS_L','车行道','车行线','GPSCOMMON'],
        blocks:false,
        text:{
            'GPSCOMMON':'标识标注'
        },
        new:{
            'SS_L':'DN100'
        },
        clayer: {
            'GPSCOMMON': {
                '255': 'DN120',
                '32639': 'DN150',
                '65280': 'DN160',
                '65535': 'DN200',
                '16711680': 'DN250',
                '8421504': 'DN165',
                '16711935': 'DN300',
                '16776960': 'DN400',
            }
        },
        tlayers:{
            '标识标注':{c:'11382189',b:false},
            '车行道':{c:'11382189',b:false},
            '车行线':{c:'11382189',b:false},
            'SS_L':{c:'11382189',b:false},
            'DN100':{c:'255',b:true},
            'DN120':{c:'255',b:true},
            'DN150':{c:'32639',b:true},
            'DN160':{c:'65280',b:true},
            'DN165':{c:'8421504',b:true},
            'DN200':{c:'65535',b:true},
            'DN300':{c:'16711935',b:true},
            'DN400':{c:'16776960',b:true},
            'DN250':{c:'16711680',b:true}
        },
        merge: ['车行道','车行线']
    }
    dxfstruct.setShowLayers(newLayer)
    dxfstruct.resetDxf('user')

    console.log('dxfstruct',dxfstruct.dxf.entities.length)
    fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf));
    //console.log(dxfstruct.getDxfStruct())
});